﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data.Common;
    using WMS6.Common;
    using WMS6.DALFactory;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;

    public class ShipmentContainerBLL
    {
        private static readonly ICartonDA cartonDA = DataAccess.CreateCartonDA();
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IOrderDetailDA orderDetailDA = DataAccess.CreateOrderDetailDA();
        private static readonly IOrdersDA ordersDA = DataAccess.CreateOrdersDA();
        private PubParasInfo pubParasInfo;
        private static readonly IShipmentContainerDA shipmentContainerDA = DataAccess.CreateShipmentContainerDA();

        public ShipmentContainerBLL()
        {
            this.pubParasInfo = null;
        }

        public ShipmentContainerBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public ShipmentContainerBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string DeleteShipmentContainer(List<string> shipmentContainerID)
        {
            string ShipmentContainer = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                List<ShipmentContainerInfo> shipmentContainerInfos = new List<ShipmentContainerInfo>();
                ShipmentContainerInfo shipmentContainerInfo = null;
                foreach (string id in shipmentContainerID)
                {
                    shipmentContainerInfo = shipmentContainerDA.GetShipmentContainerByID(dataBase, tran, id, this.dataBaseID[0]);
                    shipmentContainerInfos.Add(shipmentContainerInfo);
                }
                AuditDataBLL auditDataBLL = new AuditDataBLL();
                if (shipmentContainerDA.DeleteShipmentContainer(dataBase, tran, shipmentContainerID, this.dataBaseID[0]) > 0)
                {
                    for (int i = 0; shipmentContainerID.Count > i; i++)
                    {
                        auditDataBLL.InsertAuditData<ShipmentContainerInfo>(dataBase, tran, shipmentContainerInfos[i], null, AuditAction.Delete, this.pubParasInfo.UserID, "SHIPMENT_CONTAINER", this.dataBaseID[0]);
                        ShipmentContainer = ShipmentContainer + shipmentContainerID[i] + ";";
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ShipmentContainer;
        }

        public ShipmentContainerInfo GetShipmentContainerByID(string shipmentcontainerID, string orderID)
        {
            return shipmentContainerDA.GetShipmentContainerByID(shipmentcontainerID, orderID, this.dataBaseID[0]);
        }

        public List<ShipmentContainerInfo> GetShipmentContainerByOrderID(string OrderID)
        {
            return shipmentContainerDA.GetShipmentContainerByOrderID(OrderID, this.dataBaseID[0]);
        }

        public string InsertShipmentContainer(List<ShipmentContainerInfo> shipmentcontainerList)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ShipmentContainer = string.Empty;
            try
            {
                ISkuDA skuDA = DataAccess.CreateSkuDA();
                foreach (ShipmentContainerInfo shipmentcontainerInfo in shipmentcontainerList)
                {
                    shipmentcontainerInfo.UpdatedBy = this.pubParasInfo.UserID;
                    shipmentcontainerInfo.CreatedDate = DateTime.Now;
                    shipmentcontainerInfo.UpdatedDate = DateTime.Now;
                    SkuInfo skuinfo = skuDA.GetSkuByID(dataBase, tran, shipmentcontainerInfo.OwnerID, shipmentcontainerInfo.SkuID, this.dataBaseID[0]);
                    if (skuinfo != null)
                    {
                        shipmentcontainerInfo.Value = Convert.ToDouble((decimal) (shipmentcontainerInfo.Qty * skuinfo.SalePrice));
                    }
                    if (!cartonDA.CheckCartonUniqueByCartonType(dataBase, tran, shipmentcontainerInfo.ContainerType, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F7600_001", this.pubParasInfo.UserLanguage, new List<string> { shipmentcontainerInfo.ContainerType });
                    }
                    if (shipmentContainerDA.CheckShipmentContainerIDUnique(dataBase, tran, shipmentcontainerInfo.ContainerID, shipmentcontainerInfo.OrderID, shipmentcontainerInfo.SkuID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F7600_002", this.pubParasInfo.UserLanguage, new List<string> { shipmentcontainerInfo.ContainerID });
                    }
                    if (shipmentContainerDA.InsertShipmentContainer(dataBase, tran, shipmentcontainerInfo, this.dataBaseID[0]) > 0)
                    {
                        new AuditDataBLL().InsertAuditData<ShipmentContainerInfo>(dataBase, tran, null, shipmentcontainerInfo, AuditAction.Insert, this.pubParasInfo.UserID, "SHIPMENT_CONTAINER", this.dataBaseID[0]);
                        ShipmentContainer = ShipmentContainer + shipmentcontainerInfo.ContainerID + ",";
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ShipmentContainer;
        }

        public string ScanShipmentContainer(List<ShipmentContainerInfo> shipmentcontainerList)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ShipmentContainer = string.Empty;
            try
            {
                foreach (ShipmentContainerInfo info in shipmentcontainerList)
                {
                    if (!shipmentContainerDA.CheckShipmentContainerIDUnique(dataBase, tran, info.ContainerID, info.OrderID, this.dataBaseID[0]))
                    {
                        ShipmentContainerInfo Sc;
                        Sc = new ShipmentContainerInfo();
                        Sc.ContainerID = info.ContainerID;
                        Sc.ContainerType = info.ContainerType;
                        Sc.OrderID = info.OrderID;
                        Sc.IsActive = "N";
                        Sc.Length = info.Length;
                        Sc.MultiFlag = info.MultiFlag;
                        Sc.Qty = 0M;
                        Sc.Status = "OK";
                        Sc.TotalQty = 0M;
                        Sc.UomID = "";
                        Sc.SkuID = "";
                        Sc.Value = info.Value;
                        Sc.Volume = info.Volume;
                        Sc.Weight = info.Weight;
                        Sc.Width = info.Width;
                        Sc.ExternOrderID = "";
                        Sc.ExternLineID = "";
                        Sc.Barcode = "";
                        Sc.OwnerID = "";
                        Sc.CreatedBy = info.CreatedBy;
                        Sc.UpdatedBy = Sc.CreatedBy;
                        shipmentContainerDA.InsertShipmentContainer(dataBase, tran, Sc, this.dataBaseID[0]);
                    }
                    info.UpdatedBy = this.pubParasInfo.UserID;
                    if (shipmentContainerDA.CheckShipmentContainerIDUnique(dataBase, tran, info.ContainerID, info.OrderID, info.SkuID, info.OrderLineID, this.dataBaseID[0]))
                    {
                        if (shipmentContainerDA.ScanUpdateShipmentContainer(dataBase, tran, info, this.dataBaseID[0]) > 0)
                        {
                            ShipmentContainer = info.SkuID;
                        }
                    }
                    else if (shipmentContainerDA.InsertShipmentContainer(dataBase, tran, info, this.dataBaseID[0]) > 0)
                    {
                        ShipmentContainer = info.SkuID;
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ShipmentContainer;
        }

        public string ShippingContainerDetailImportByData(string[][] ImportByData)
        {
            Exception ex;
            try
            {
                int i;
                string whLoginID = this.dataBaseID[0];
                List<ShipmentContainerInfo> shipmentcontainerList = new List<ShipmentContainerInfo>();
                for (i = 1; i < ImportByData.Length; i++)
                {
                    int CS00002;
                    ShipmentContainerInfo shipmentContainerInfo = new ShipmentContainerInfo {
                        CreatedBy = this.pubParasInfo.UserID,
                        UpdatedBy = this.pubParasInfo.UserID
                    };
                    for (int j = 0; j < ImportByData[i].Length; j++)
                    {
                        switch (ImportByData[0][j].ToUpper().Trim())
                        {
                            case "CONTAINER_ID":
                            {
                                if (!string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    shipmentContainerInfo.ContainerID = ImportByData[i][j];
                                }
                                continue;
                            }
                            case "CONTAINER_TYPE":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    break;
                                }
                                shipmentContainerInfo.ContainerType = ImportByData[i][j];
                                continue;
                            }
                            case "PARENT_CONTAINER_ID":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_025A;
                                }
                                shipmentContainerInfo.ParentContainerID = ImportByData[i][j];
                                continue;
                            }
                            case "LENGTH":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_0294;
                                }
                                shipmentContainerInfo.Length = double.Parse(ImportByData[i][j]);
                                continue;
                            }
                            case "WIDTH":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_02D2;
                                }
                                shipmentContainerInfo.Width = double.Parse(ImportByData[i][j]);
                                continue;
                            }
                            case "HEIGHT":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_0310;
                                }
                                shipmentContainerInfo.Height = double.Parse(ImportByData[i][j]);
                                continue;
                            }
                            case "VOLUME":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_034E;
                                }
                                shipmentContainerInfo.Volume = double.Parse(ImportByData[i][j]);
                                continue;
                            }
                            case "WEIGHT":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_038C;
                                }
                                shipmentContainerInfo.Weight = double.Parse(ImportByData[i][j]);
                                continue;
                            }
                            case "VALUE":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_03CA;
                                }
                                shipmentContainerInfo.Value = double.Parse(ImportByData[i][j]);
                                continue;
                            }
                            case "WORKER_ID":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_0403;
                                }
                                shipmentContainerInfo.WorkerID = ImportByData[i][j];
                                continue;
                            }
                            case "ORDER_ID":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_0438;
                                }
                                shipmentContainerInfo.OrderID = ImportByData[i][j];
                                continue;
                            }
                            case "ORDER_LINE_ID":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_0472;
                                }
                                shipmentContainerInfo.OrderLineID = int.Parse(ImportByData[i][j]);
                                continue;
                            }
                            case "OWNER_ID":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_04A3;
                                }
                                shipmentContainerInfo.OwnerID = ImportByData[i][j];
                                continue;
                            }
                            case "SKU_ID":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_04D8;
                                }
                                shipmentContainerInfo.SkuID = ImportByData[i][j];
                                continue;
                            }
                            case "QTY":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_0512;
                                }
                                shipmentContainerInfo.Qty = decimal.Parse(ImportByData[i][j]);
                                continue;
                            }
                            case "UOM_ID":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_0548;
                                }
                                shipmentContainerInfo.UomID = ImportByData[i][j];
                                continue;
                            }
                            case "BARCODE":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_057D;
                                }
                                shipmentContainerInfo.Barcode = ImportByData[i][j];
                                continue;
                            }
                            case "CONTAINER_NO":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_05AF;
                                }
                                shipmentContainerInfo.ContainerNO = ImportByData[i][j];
                                continue;
                            }
                            case "SEAL_NO":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    goto Label_05E1;
                                }
                                shipmentContainerInfo.SealNO = ImportByData[i][j];
                                continue;
                            }
                            default:
                            {
                                continue;
                            }
                        }
                        shipmentContainerInfo.ContainerType = "Small";
                        continue;
                    Label_025A:
                        shipmentContainerInfo.ParentContainerID = "";
                        continue;
                    Label_0294:
                        shipmentContainerInfo.Length = 0.0;
                        continue;
                    Label_02D2:
                        shipmentContainerInfo.Width = 0.0;
                        continue;
                    Label_0310:
                        shipmentContainerInfo.Height = 0.0;
                        continue;
                    Label_034E:
                        shipmentContainerInfo.Volume = 0.0;
                        continue;
                    Label_038C:
                        shipmentContainerInfo.Weight = 0.0;
                        continue;
                    Label_03CA:
                        shipmentContainerInfo.Value = 0.0;
                        continue;
                    Label_0403:
                        shipmentContainerInfo.WorkerID = "";
                        continue;
                    Label_0438:
                        shipmentContainerInfo.OrderID = "";
                        continue;
                    Label_0472:
                        shipmentContainerInfo.OrderLineID = 0;
                        continue;
                    Label_04A3:
                        shipmentContainerInfo.OwnerID = "";
                        continue;
                    Label_04D8:
                        shipmentContainerInfo.SkuID = "";
                        continue;
                    Label_0512:
                        shipmentContainerInfo.Qty = 0M;
                        continue;
                    Label_0548:
                        shipmentContainerInfo.UomID = "";
                        continue;
                    Label_057D:
                        shipmentContainerInfo.Barcode = "";
                        continue;
                    Label_05AF:
                        shipmentContainerInfo.ContainerNO = "";
                        continue;
                    Label_05E1:
                        shipmentContainerInfo.SealNO = "";
                    }
                    if (string.IsNullOrEmpty(shipmentContainerInfo.ContainerID))
                    {
                        CS00002 = i + 1;
                        throw new Exception("行号(" + CS00002.ToString() + ")容器ID不能为空!");
                    }
                    if (string.IsNullOrEmpty(shipmentContainerInfo.OrderID))
                    {
                        CS00002 = i + 1;
                        throw new Exception("行号(" + CS00002.ToString() + ")订单号不能为空!");
                    }
                    if (!ordersDA.CheckOrdersIDUnique(shipmentContainerInfo.OrderID, whLoginID))
                    {
                        CS00002 = i + 1;
                        throw new Exception("行号(" + CS00002.ToString() + ")订单号有误，系统不存在该发货订单!");
                    }
                    if (!string.IsNullOrEmpty(shipmentContainerInfo.SkuID))
                    {
                        object[] CS00004;
                        CS00002 = shipmentContainerInfo.OrderLineID;
                        OrderDetailInfo orderDetailInfo = orderDetailDA.GetOrderDetailByID(shipmentContainerInfo.OrderID, CS00002.ToString(), whLoginID, this.pubParasInfo);
                        if (orderDetailInfo == null)
                        {
                            CS00002 = i + 1;
                            throw new Exception("行号(" + CS00002.ToString() + ")订单行有误，订单不存在该明细行!");
                        }
                        if (orderDetailInfo.SkuID.ToUpper() != shipmentContainerInfo.SkuID.ToUpper())
                        {
                            CS00004 = new object[5];
                            CS00004[0] = "行号(";
                            CS00002 = i + 1;
                            CS00004[1] = CS00002.ToString();
                            CS00004[2] = ")货品代码有误，订单行(";
                            CS00004[3] = shipmentContainerInfo.OrderLineID;
                            CS00004[4] = ")不存在该货品!";
                            throw new Exception(string.Concat(CS00004));
                        }
                        if (orderDetailInfo.OwnerID.ToUpper() != shipmentContainerInfo.OwnerID.ToUpper())
                        {
                            CS00004 = new object[] { "行号(", (i + 1).ToString(), ")货主代码有误，订单行(", shipmentContainerInfo.OrderLineID, ")不存在该货主!" };
                            throw new Exception(string.Concat(CS00004));
                        }
                    }
                    shipmentContainerInfo.CreatedBy = this.pubParasInfo.UserID;
                    shipmentContainerInfo.UpdatedBy = this.pubParasInfo.UserID;
                    shipmentContainerInfo.CreatedDate = DateTime.Now;
                    shipmentContainerInfo.UpdatedDate = DateTime.Now;
                    shipmentContainerInfo.ExternOrderID = "";
                    shipmentContainerInfo.ExternLineID = "";
                    shipmentContainerInfo.Status = "OK";
                    shipmentContainerInfo.MultiFlag = "Y";
                    shipmentContainerInfo.TotalQty = shipmentContainerInfo.Qty;
                    shipmentcontainerList.Add(shipmentContainerInfo);
                }
                if ((shipmentcontainerList != null) && (shipmentcontainerList.Count > 0))
                {
                    DataBase dataBase = new DataBase();
                    DbConnection conn = dataBase.connection;
                    conn.Open();
                    DbTransaction tran = conn.BeginTransaction();
                    try
                    {
                        shipmentContainerDA.DeleteShipmentContainerByWhere(dataBase, tran, shipmentcontainerList[0].OrderID, "", whLoginID);
                        for (i = 0; i < shipmentcontainerList.Count; i++)
                        {
                            if (string.IsNullOrEmpty(shipmentcontainerList[i].SkuID.Trim()) && !string.IsNullOrEmpty(shipmentcontainerList[i].ContainerType.Trim()))
                            {
                                if (!shipmentContainerDA.CheckShipmentContainerIDUnique(dataBase, tran, shipmentcontainerList[i].ContainerID, shipmentcontainerList[i].OrderID, "", this.dataBaseID[0]))
                                {
                                    shipmentcontainerList[i].IsActive = "N";
                                    shipmentContainerDA.InsertShipmentContainer(dataBase, tran, shipmentcontainerList[i], whLoginID);
                                }
                            }
                            else
                            {
                                shipmentcontainerList[i].IsActive = "Y";
                                shipmentContainerDA.InsertShipmentContainer(dataBase, tran, shipmentcontainerList[i], whLoginID);
                                ShipmentContainerInfo scInfo = shipmentContainerDA.GetShipmentContainerByID(dataBase, tran, shipmentcontainerList[i].ContainerID, whLoginID);
                                if (scInfo != null)
                                {
                                    scInfo.TotalQty += shipmentcontainerList[i].Qty;
                                    scInfo.Length += shipmentcontainerList[i].Length;
                                    scInfo.Width += shipmentcontainerList[i].Width;
                                    scInfo.Height += shipmentcontainerList[i].Height;
                                    scInfo.Volume += shipmentcontainerList[i].Volume;
                                    scInfo.Weight += shipmentcontainerList[i].Weight;
                                    scInfo.Value += shipmentcontainerList[i].Value;
                                    scInfo.UpdatedBy = this.pubParasInfo.UserID;
                                    shipmentContainerDA.UpdateShipmentContainer(dataBase, tran, scInfo, whLoginID);
                                }
                            }
                        }
                        tran.Commit();
                    }
                    catch (Exception exception1)
                    {
                        ex = exception1;
                        tran.Rollback();
                        CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception exception2)
            {
                ex = exception2;
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return "";
        }

        public string UpdateShipmentContainer(List<ShipmentContainerInfo> shipmentcontainerList)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ShipmentContainer = string.Empty;
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            try
            {
                foreach (ShipmentContainerInfo shipmentcontainerInfo in shipmentcontainerList)
                {
                    if (shipmentcontainerInfo.IsActive == "N")
                    {
                        shipmentcontainerInfo.UpdatedBy = this.pubParasInfo.UserID;
                        shipmentcontainerInfo.UpdatedDate = DateTime.Now;
                        shipmentContainerDA.UpdateShipmentContainer(dataBase, tran, shipmentcontainerInfo, this.dataBaseID[0]);
                    }
                    else if (shipmentcontainerInfo.Qty == 0M)
                    {
                        if (shipmentContainerDA.DeleteShipmentContainerByOrderLineID(dataBase, tran, shipmentcontainerInfo.ContainerID, shipmentcontainerInfo.OrderID, shipmentcontainerInfo.SkuID, shipmentcontainerInfo.OrderLineID, this.dataBaseID[0]) > 0)
                        {
                            auditDataBLL.InsertAuditData<ShipmentContainerInfo>(dataBase, tran, shipmentcontainerInfo, null, AuditAction.Delete, this.pubParasInfo.UserID, "SHIPMENT_CONTAINER", this.dataBaseID[0]);
                            ShipmentContainer = shipmentcontainerInfo.ContainerID;
                        }
                    }
                    else
                    {
                        shipmentcontainerInfo.UpdatedBy = this.pubParasInfo.UserID;
                        if (shipmentContainerDA.CheckShipmentContainerIDUnique(dataBase, tran, shipmentcontainerInfo.ContainerID, shipmentcontainerInfo.OrderID, shipmentcontainerInfo.SkuID, shipmentcontainerInfo.OrderLineID, this.dataBaseID[0]))
                        {
                            ShipmentContainerInfo oldShipmentContainerInfo = shipmentContainerDA.GetShipmentContainerByID(dataBase, tran, shipmentcontainerInfo.ContainerID, this.dataBaseID[0]);
                            if (shipmentContainerDA.UpdateShipmentContainer(dataBase, tran, shipmentcontainerInfo, this.dataBaseID[0]) > 0)
                            {
                                ShipmentContainer = shipmentcontainerInfo.ContainerID;
                                auditDataBLL.InsertAuditData<ShipmentContainerInfo>(dataBase, tran, oldShipmentContainerInfo, shipmentcontainerInfo, AuditAction.Update, this.pubParasInfo.UserID, "SHIPMENT_CONTAINER", this.dataBaseID[0]);
                            }
                        }
                        else if (shipmentContainerDA.InsertShipmentContainer(dataBase, tran, shipmentcontainerInfo, this.dataBaseID[0]) > 0)
                        {
                            ShipmentContainer = shipmentcontainerInfo.ContainerID;
                            auditDataBLL.InsertAuditData<ShipmentContainerInfo>(dataBase, tran, null, shipmentcontainerInfo, AuditAction.Insert, this.pubParasInfo.UserID, "SHIPMENT_CONTAINER", this.dataBaseID[0]);
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ShipmentContainer;
        }
    }
}

